package com.rayworks.richtextview.ui;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.InputType;
import android.view.View;
import android.widget.Button;

import com.rayworks.library.GapFillTextView;
import com.rayworks.richtextview.R;

import java.util.HashMap;

public class MainActivity extends AppCompatActivity {

    private Button buttonClear;
    private Button buttonSet;
    private GapFillTextView richText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        HashMap<Integer, Integer> inputTypeMap = new HashMap<>();
        inputTypeMap.put(1, GapFillTextView.BLANK_TYPE_NUMBER);
        inputTypeMap.put(2, GapFillTextView.BLANK_TYPE_SELECTIONS);
        richText.setBlankTypeMap(inputTypeMap);
        HashMap<Integer, String> titleMap = new HashMap<>();
        titleMap.put(0, "名字");
        titleMap.put(1, "年龄");
        richText.setBlankTitleMap(titleMap);
        HashMap<Integer, String[]> selectionsMap = new HashMap<>();
        selectionsMap.put(2, new String[]{"东区", "南区","西区", "北区"});
        richText.setBlankSelectionsMap(selectionsMap);
        buttonClear.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                richText.reset();
            }
        });
        buttonSet.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                HashMap<Integer, String> filledTexts = new HashMap<>();
                filledTexts.put(0, "Skean");
                filledTexts.put(1, "23");
                filledTexts.put(2, "沙溪");
                richText.setFilledTexts(filledTexts, true);
            }
        });
    }

    private void initView() {
        buttonClear = findViewById(R.id.buttonClear);
        buttonSet = findViewById(R.id.buttonSet);
        richText = findViewById(R.id.richText);
    }
}
